﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace weba
{
    public class dl
    {
        public static void CreatCookies(string cookieName, int time, string strValue, string strDomain)
        {
            HttpCookie aCookie;
            aCookie = new HttpCookie(cookieName);
            aCookie.Value = HttpContext.Current.Server.HtmlEncode(strValue);
            aCookie.Expires = DateTime.Now.AddHours(time);
            if (!string.IsNullOrEmpty(strDomain))
            {
                aCookie.Domain = strDomain;
            }
            HttpContext.Current.Response.Cookies.Add(aCookie);
        }
        public static string GetCookies(string strKey)
        {
            return (HttpContext.Current.Request.Cookies[strKey] != null) ? HttpContext.Current.Request.Cookies[strKey].Value : "";
        }
        public static void CheckState(string strKey, string strThrowUrl, string strMes)
        {
            string strSession = GetSession(strKey);
            if (string.IsNullOrEmpty(strSession))
            {
                System.Web.HttpContext.Current.Response.Write("<script>");
                System.Web.HttpContext.Current.Response.Write("alert(\"" + strMes + "\");");
                System.Web.HttpContext.Current.Response.Write("top.location.href=\"" + strThrowUrl + "\";");
                System.Web.HttpContext.Current.Response.Write("</script>");
                System.Web.HttpContext.Current.Response.End();
            }
        }
        public static string GetSession(string strKey)
        {
            return (HttpContext.Current.Session[strKey] != null) ? HttpContext.Current.Session[strKey].ToString() : "";

        }
        public static string isloged()
        {
            string strSession = GetSession("User_ID");
            if (strSession == GetCookies("User_Name") && strSession != "")
            {
                return strSession + "已登陆";
            }
            else
            {
                return "请登录";
            }
        }
        public static bool islogedtf()
        {
            string strSession = GetSession("User_ID");
            if (strSession == GetCookies("User_Name") && strSession != "")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static void RemoveAllSession()
        {
            HttpContext.Current.Session.RemoveAll();
        }
        public static string UserState(object strValue, object strService)
        {
            string strState = "<font color=green>公用客户</font>";
            switch (strValue.ToString())
            {
                case "0":
                    break;
                case "1":
                    strState = "<font color=red>占用客户</font>[" + strService.ToString().Trim() + "]";
                    break;
                case "2":
                    strState = "成交客户[" + strService.ToString().Trim() + "]";
                    break;
                default:
                    strState = "<font color=#666666>未知状态</font>";
                    break;
            }
            return strState;
        }
    }
}